#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

struct Edge {
	int to, pre, nxt, c;
} e[13000];
int e_cnt, n, m, q, dis[2600], ts, te;
int heads[2600];
void add(int pre, int to, int c) {
	e[++e_cnt].to = to;
	e[e_cnt].pre = pre;
	e[e_cnt].c = c;
	e[e_cnt].nxt = heads[pre];
	heads[pre] = e_cnt;
}

priority_queue<pair<int, int> > que;
void dij() {
	dis[ts] = 0;
	que.push(make_pair(0, ts));
	while (que.size()) {
		int x = que.top().second;
		int d = -que.top().first;
		que.pop();
		if (d != dis[x]) {
			continue;
		}
		for (int i = heads[x]; i; i = e[i].nxt) {
			int y = e[i].to;
			int z = e[i].c;
			if (dis[y] > dis[x] + z) {
				dis[y] = dis[x] + z;
				que.push(make_pair(-dis[y], y));
			}
		}
	}
}
int main() {
	cin >> n >> m;
	memset(dis, 0x3f, sizeof(dis));
	for (int i = 0; i < m; i++) {
		int tmp1, tmp2, tmp3;
		cin >> tmp1 >> tmp2 >> tmp3;
		add(tmp1, tmp2, tmp3);
		add(tmp2, tmp1, tmp3);
	}
	cin >> q;
	for (int i = 0; i < q; ++i) {
		cin >> ts >> te;
		dij();
		int tmp = dis[te];
		for (int i = 1; i <= e_cnt; ++i) {
			if (e[i].c <= k)
		}
	}
	cout << dis[te];
	return 0;
}